package com.vic.mvc.testsome;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class T2 {

	static List<Tc> list = new ArrayList<Tc>();
	
	static List<Tc1> list1 = new ArrayList<Tc1>();
	
	public static void main(String[] args) throws Exception {
		
		test2();
	}
	
	public static void test1(){
		initList();
		List<Tc> other = new ArrayList<Tc>();
		other.addAll(list);
		Collections.copy(other, list);
		other.get(1).addAge(12);
		other.get(2).addAge(30);
		
		
		for(int i=0; i<4; i++) {
			System.out.println("old:" + list.get(i) +"\t\tnew:" + other.get(i));
		}
	}
	
	public static void test2(){
		initList1();
		List<Tc1> other = new ArrayList<Tc1>();
		other.addAll(list1);
		Collections.copy(other, list1);
		other.get(1).addAge(12);
		other.get(2).addAge(30);
		
		
		for(int i=0; i<4; i++) {
			System.out.println("old:" + list1.get(i) +"\t\tnew:" + other.get(i));
		}
	}
	
	
	public static void initList(){
		if(list.isEmpty()) {
			list.add(new Tc(10, "aaa"));
			list.add(new Tc(15, "bbb"));
			list.add(new Tc(20, "ccc"));
			list.add(new Tc(30, "ddd"));
		}
	}
	
	public static void initList1(){
		if(list1.isEmpty()) {
			list1.add(new Tc1(10, "aaa"));
			list1.add(new Tc1(15, "bbb"));
			list1.add(new Tc1(20, "ccc"));
			list1.add(new Tc1(30, "ddd"));
		}
	}

}

class Tc{
	int age;
	String name;
	
	
	
	public Tc(int age, String name) {
		super();
		this.age = age;
		this.name = name;
	}
	
	
	public void addAge(int a){
		this.age = age +a;
	}
	
	public void addAge(){
		this.age = age +1;
	}
	
	
	@Override
	public String toString() {
		return "Tc [age=" + age + ", name=" + name + "]";
	}


	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	
}


class Tc1 implements Cloneable{
	int age;
	String name;
	
	
	
	@Override
	protected Object clone() throws CloneNotSupportedException {
		return super.clone();
	}


	public Tc1(int age, String name) {
		super();
		this.age = age;
		this.name = name;
	}
	
	
	public void addAge(int a){
		this.age = age +a;
	}
	
	public void addAge(){
		this.age = age +1;
	}
	
	
	@Override
	public String toString() {
		return "Tc [age=" + age + ", name=" + name + "]";
	}


	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	
}

